const mkdirp = require('mkdirp');
const inquirer = require('inquirer');
const path = require("path");
const {existsSync} = require('fs-extra');
const chalk = require('chalk');

module.exports = class FilesManager {
    constructor(name) {
        this.name = name;
    }

    async createProjectDir() {
        /*2、 创建项目文件夹 */
        const root = path.resolve(process.cwd(), this.name);
        let made = '';
        console.log('root', root);
        if (!existsSync(root)) {
            made = mkdirp.sync(root);
        } else {
            const result = await inquirer.prompt([
                {
                    type: 'confirm',
                    message: '文件夹已存在,是否覆盖：',
                    name: 'overwrite',
                    default: false
                }
            ])
            if (!result.overwrite) {
                return Promise.reject();
            }
            made = root;
        }
        console.log('made', made)
        return Promise.resolve(made);

    }

    destinationRoot(dir) {
        process.chdir(dir);
        process.env.cwd = dir;
    }

}
